package com.yw.utils;

import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.web.client.RestTemplate;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

//需要去浏览器下载脚本到本地的时候用到此工具类，如果脚本本来就在本地则不需要
public class PythonScriptDownloader {
    public static void downloadScript(String sourcePath, String targetPath) {
        try {
            // 将源路径和目标路径转换为 Path 对象
            Path source = Paths.get(sourcePath);
            Path target = Paths.get(targetPath);

            // 确保源文件存在
            if (!Files.exists(source)) {
                throw new IOException("Source file does not exist: " + sourcePath);
            }

            // 确保目标目录存在
            Files.createDirectories(target.getParent());

            // 将源文件的内容复制到目标文件
            Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);

            System.out.println("File copied successfully from " + sourcePath + " to " + targetPath);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
